package cn.itcast.bos.web.action.transit;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.xml.resolver.helpers.PublicId;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.transit.TransitInfoService;
import cn.itcast.bos.web.action.common.BaseAction;

public class TransitInfoAction extends BaseAction<TransitInfo>{
	@Resource
	private TransitInfoService service;
	
	private String wayBillIds;
	
	public void setWayBillIds(String wayBillIds) {
		this.wayBillIds = wayBillIds;
	}

	@Action(value="transit_create",results={@Result(name="success",type="json")})
	public String creat(){
		Map<String, Object> results = new HashMap<>();
		//调用业务层保存transitinfo信息
		try {
			service.creatTransits(wayBillIds);
			//成功
			results.put("success", true);
			results.put("msg","开启中转配送成功");
		} catch (Exception e) {
			e.printStackTrace();
			results.put("success",false);
			results.put("msg","开启中装配送失败");
		}
		ActionContext.getContext().getValueStack().push(results);
		return SUCCESS;
	}
	
	@Action(value="transit_pageQuery",results={@Result(name="success",type="json")})
	public String transit_pageQuery(){
		//无条件的分页查询
		Pageable pageable = new PageRequest(page-1, rows);
		Page<TransitInfo> pageData = service.findAll(pageable);
		pushPageDataToValueStack(pageData);
		return SUCCESS;
	}
}
